package com.vehicle.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vehicle.bean.DataGridView;
import com.vehicle.mapper.BtypeMapper;
import com.vehicle.mapper.Btype_typeMapper;
import com.vehicle.pojo.Btype;
import com.vehicle.pojo.Btype_type;
import com.vehicle.service.BtypeService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BtypeServiceImpl implements BtypeService {
    @Autowired
    private BtypeMapper btypeMapper;
    @Autowired
    private Btype_typeMapper btype_typeMapper;

    //分页
    @Transactional(
        propagation = Propagation.NOT_SUPPORTED
    )
    public DataGridView findBtypeBypage(Btype btype) {
        Page<Object> page = PageHelper.startPage(btype.getPage(), btype.getLimit());
        List<Btype> btypes = this.btypeMapper.selectBtypeByPage(btype);
        DataGridView dataGridView = new DataGridView();
        dataGridView.setCount(page.getTotal());
        dataGridView.setData(btypes);
        return dataGridView;
    }
    //所有
    @Override
    public DataGridView findAllBtype() {
        Btype btype = new Btype();
        List<Btype> btypes =btypeMapper.selectBtypeByPage(btype);
        DataGridView dataGridView = new DataGridView();
        dataGridView.setData(btypes);
        return dataGridView;
    }

    //查询时汽车厂商的往来单位
    @Override
    public List<Btype> findBtypeWithCar() {
        return btypeMapper.btypeBuyCar();
    }

    //查询所有往来单位类型
    @Override
    public List<Btype_type> findBtype_bypes() {
        return btype_typeMapper.selectAllBtype_type();
    }

    //增加
    @Override
    public void addBtype(Btype btype) {
        btypeMapper.insertBtype(btype);
    }

    //修改
    @Override
    public void editBtype(Btype btype) {
        btypeMapper.updateBtype(btype);
    }

    //单个删除
    @Override
    public void updateStatus(Integer btypeid) {
        btypeMapper.updateStatus(btypeid);
    }

    //批量删除
    @Override
    public void updateStatusBatch(Integer[] btypeids) {
        if (btypeids!=null&&btypeids.length>0){
            for (Integer btypeid:btypeids
                 ) {
                btypeMapper.updateStatus(btypeid);
            }
        }
    }
}